home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-desktop-9.10-i386-PL.iso / casper / filesystem.squashfs / usr / lib / xulrunner-1.9.1.5 / modules / debug.js next >
Text File  |  2009-11-09  |  3KB  |  83 lines

  1. //@line 44 "/build/buildd/xulrunner-1.9.1-1.9.1.5+nobinonly/build-tree/mozilla/toolkit/content/debug.js"
  2.  
  3. var EXPORTED_SYMBOLS = ["NS_ASSERT"];
  4.  
  5. var gTraceOnAssert = true;
  6.  
  7. /**
  8.  * This function provides a simple assertion function for JavaScript.
  9.  * If the condition is true, this function will do nothing.  If the
  10.  * condition is false, then the message will be printed to the console
  11.  * and an alert will appear showing a stack trace, so that the (alpha
  12.  * or nightly) user can file a bug containing it.  For future enhancements, 
  13.  * see bugs 330077 and 330078.
  14.  *
  15.  * To suppress the dialogs, you can run with the environment variable
  16.  * XUL_ASSERT_PROMPT set to 0 (if unset, this defaults to 1).
  17.  *
  18.  * @param condition represents the condition that we're asserting to be
  19.  *                  true when we call this function--should be
  20.  *                  something that can be evaluated as a boolean.
  21.  * @param message   a string to be displayed upon failure of the assertion
  22.  */
  23.  
  24. function NS_ASSERT(condition, message) {
  25.   if (condition)
  26.     return;
  27.  
  28.   var releaseBuild = true;
  29.   var defB = Components.classes["@mozilla.org/preferences-service;1"]
  30.                        .getService(Components.interfaces.nsIPrefService)
  31.                        .getDefaultBranch(null);
  32.   try {
  33.     switch (defB.getCharPref("app.update.channel")) {
  34.       case "nightly":
  35.       case "beta":
  36.       case "default":
  37.         releaseBuild = false;
  38.     }
  39.   } catch(ex) {}
  40.  
  41.   var caller = arguments.callee.caller;
  42.   var assertionText = "ASSERT: " + message + "\n";
  43.  
  44.   if (releaseBuild) {
  45.     // Just report the error to the console
  46.     Components.utils.reportError(assertionText);
  47.     return;
  48.   }
  49.  
  50.   // Otherwise, dump to stdout and launch an assertion failure dialog
  51.   dump(assertionText);
  52.  
  53.   var stackText = "";
  54.   if (gTraceOnAssert) {
  55.     stackText = "Stack Trace: \n";
  56.     var count = 0;
  57.     while (caller) {
  58.       stackText += count++ + ":" + caller.name + "(";
  59.       for (var i = 0; i < caller.arguments.length; ++i) {
  60.         var arg = caller.arguments[i];
  61.         stackText += arg;
  62.         if (i < caller.arguments.length - 1)
  63.           stackText += ",";
  64.       }
  65.       stackText += ")\n";
  66.       caller = caller.arguments.callee.caller;
  67.     }
  68.   }
  69.  
  70.   var environment = Components.classes["@mozilla.org/process/environment;1"].
  71.                     getService(Components.interfaces.nsIEnvironment);
  72.   if (environment.exists("XUL_ASSERT_PROMPT") &&
  73.       !parseInt(environment.get("XUL_ASSERT_PROMPT")))
  74.     return;
  75.  
  76.   var source = null;
  77.   if (this.window)
  78.     source = this.window;
  79.   var ps = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].
  80.            getService(Components.interfaces.nsIPromptService);
  81.   ps.alert(source, "Assertion Failed", assertionText + stackText);
  82. }
  83.